/**
 * Created by Maxwell on 2016/9/26.
 */
"use strict";
let request = require("../../common/util/request"),
    config = require('../../config');
let head = new Buffer(`${config['client_id']}:${config['client_secret']}`).toString('base64');

let CommonService = function () {
};


CommonService.prototype = {

    /**
     * test
     * @param params
     */
    test: function *(params) {
        return 'this is test';
    },
    /**
     * 获取客户端加密token
     * @param params
     * @returns {*}
     */
    getClientToken:function *(params) {
        var res = yield request.commonTransfer({
            uri: `${config.apiHost.uri}/Account/Token`,
            params: params,
            method: "post"
        });
        return res.body;
    },
    /**
     * 登录
     * @param params
     * @returns {*}
     */
    login: function *(params) {
        var res = yield request.commonTransfer({
            uri: config.apiHost.uri + '/Account/Token',
            params: params,
            method: "post",
            headerType:'Basic',
            token: head
        });
        return res.body;
    },
    /**
     * 获取当前登录的用户信息
     * @param params
     * @returns {*}
     */
    getCurrentUserInfo:function *(params){
        var res = yield request.ajaxTransfer({
            uri: `${config.apiHost.uri}/api/Application/Account/GetCurrentUser`,
            method: "post",
            headerType:'Bearer',
            token: params.token
        });
        return res.body;
    }
};

module.exports = new CommonService();